package ru.ifmo.ipimenov.ewf_svn.standalone.service.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import ru.ifmo.ipimenov.ewf_svn.standalone.dao.DocumentDao;
import ru.ifmo.ipimenov.ewf_svn.standalone.dao.impl.DocumentDaoHibernate;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.Document;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.User;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.State;
import ru.ifmo.ipimenov.ewf_svn.standalone.service.DocumentService;
import ru.ifmo.ipimenov.ewf_svn.standalone.ruler.RulePerformerService;

import java.util.List;

/**
 * @author: Ilya Pimenov
 * Scartel Starlab company
 */
public class DocumentServiceImpl implements DocumentService {
    /**
     * Logger for all purposes
     */
    private static Log log = LogFactory.getLog(DocumentServiceImpl.class);

    private DocumentDao dao;

    public DocumentServiceImpl() {
        dao = new DocumentDaoHibernate();
    }

    public List<Document> load(User u) {
        return dao.load(u);
    }

    public Document load(Integer id) {
        return dao.load(id);
    }

    public void save(Document d) {
        dao.save(d);
    }

    public void update(Document d) {
        dao.update(d);
    }

    public void setState(Document d, State state) {
        d.setState(state);
        dao.update(d);
        RulePerformerService.getRulePerformer().performRule(state, d);
    }
}
